package syan.sql.service.impl;

import lombok.extern.slf4j.Slf4j;
import syan.sql.mapper.RepairMapper;
import syan.sql.util.SpringContextUtil;

import java.util.Map;

/**
 * @author CHENTAIWEN
 * @create 2022/9/19 11:43
 */
@Slf4j
public class RepairQuotation implements Runnable{

    private Map<String, Object> examine;

    public RepairQuotation(Map<String, Object> examine) {
        this.examine = examine;
    }

    @Override
    public void run() {
        log.info(Thread.currentThread().getName()+"--开始处理: " + examine.get("quotation_num"));
        executeHead(examine);
        log.info(Thread.currentThread().getName()+"--处理成功: " + examine.get("quotation_num"));
        RepairServiceImpl.complete.incrementAndGet();
    }
    void executeHead(Map<String, Object> examine) {
        RepairMapper repairMapper= SpringContextUtil.getBean(RepairMapper.class);
        Integer quotationId = (Integer) examine.get("quotation_id");
        Integer sort =(Integer) examine.get("sort");
        Integer examineStatus = (Integer) examine.get("examine_status");
        String crmExmainEnum=null;
         if (examineStatus == 2) {
                if (sort == 1) {
                    crmExmainEnum = "已驳回至事业部专员";
                } else if (sort == 2) {
                    crmExmainEnum = "已驳回至事业部总经理审核";
                } else if (sort == 3) {
                    crmExmainEnum = "已驳回至市场部初审";
                }
//            crmExmainEnum="已驳回至事业部专员";
            } else if (examineStatus == 8) {
                crmExmainEnum = "作废";
            } else if (examineStatus == 1) {
                crmExmainEnum = "市场部已终审";
            } else if (examineStatus == 4) {
                crmExmainEnum = "待事业部专员审核";
            } else {
                if (sort == 1) {
                    crmExmainEnum = "待事业部总经理审核";
                } else if (sort == 2) {
                    crmExmainEnum = "待市场部审核";
                } else if (sort == 3) {
                    crmExmainEnum = "市场部已初审";
                }
            }
         try {
             repairMapper.updateStatus(crmExmainEnum, quotationId);
         }catch (Exception e){
             log.error("错误信息："+examine.get("quotation_num"));
             RepairServiceImpl.Fail.incrementAndGet();
         }
    }
}
